/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.webos.java.twitter.client;

import org.webos.java.base.Application;
import org.webos.java.base.ApplicationType;
import org.webos.java.base.Session;
import org.webos.java.base.workspace.FrameHolder;
import org.webos.java.base.workspace.Workspace;

/**
 *
 * @author Kostya
 */

@ApplicationType(code="twitter", jsClass="twitter.Application", 
    name="Twitter client", description="Simple client for Twitter", version="0.1", 
    icon="tweet_icns tweet_icn_main", errorCode=710)
public class TwitterApp extends Application{

    private String settingName = "twitter00";
    private TwitterFrame twitterFrame = null;
    private Workspace workspace = null;

    public TwitterApp(Session aSession) {
        super(aSession);
    }

    @Override
    public void initialize() {
        loadApplication();
    }



    public void loadApplication(){
        if(getOption(settingName, null)==null){
            showSettingsDialog();
        }else{
            showMainFrame();
        }
    }

    private void showSettingsDialog() {
        new SettingsDialog(this, settingName);
    }

    private void showMainFrame(){
        if(twitterFrame==null){
            workspace = new Workspace(this, "ws0");
            workspace.setType(Workspace.TYPE_FLOAT);
            workspace.setDirection(Workspace.POSITION_RIGHT);
            workspace.setHeight(400);
            FrameHolder fh = new FrameHolder(null, "main");
            workspace.setItem(fh);
            twitterFrame = new TwitterFrame(this, workspace, settingName);
            fh.addFrame(twitterFrame);
            addWorkspace(workspace);
            addFrame(twitterFrame);
            showWorkspace(workspace);
        }else{
            showWorkspace(workspace);
        }
        twitterFrame.init();
    }
}
